package com.poker.controller;

import com.poker.consts.Consts;
import com.poker.entity.ActivityUser;
import com.poker.service.ActivityUserService;
import com.poker.util.Misc;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @ClassName ActivityUserController
 * @Description TODO
 * @Author duyuanyuan
 * @Date 2019/3/13 13:46
 * @Version 1.0
 **/
@Controller
@RequestMapping("/activityUser")
public class ActivityUserController extends BaseController{

    @Resource
    private ActivityUserService activityUserService;
     /*
      * 功能描述:分页查询活动报名用户
      * @param:  * @param model
      * @param page
      * @param size
      * @return: java.lang.String
      * @auther: duyuanyuan
      * @date: 2019/3/18 10:55
      */
    @RequestMapping("/list")
    public String list(Model model,
                       @RequestParam(value = "page", defaultValue = "0") Integer page,
                       @RequestParam(value = "size", defaultValue = "50") Integer size){
        Integer managerInfo = getManagerInfo();
        Page<ActivityUser> data = activityUserService.findListAll(page,size,managerInfo);
        model.addAttribute("activityUser", new ActivityUser());
        model.addAttribute("data", data);
        return managerPage("activityUser/list");
    }
   /*
    * 功能描述:分页加条件查询活动报名用户
    * @param:  * @param model
    * @param activityUser
    * @param page
    * @param size
    * @return: java.lang.String
    * @auther: duyuanyuan
    * @date: 2019/3/18 10:55
    */
    @RequestMapping("/findQuery")
    public String list(Model model,ActivityUser activityUser,
                       @RequestParam(value = "page", defaultValue = "0") Integer page,
                       @RequestParam(value = "size", defaultValue = "50") Integer size){
        Integer managerInfo = getManagerInfo();
        Page<ActivityUser> data = activityUserService.findList(page,size,activityUser,managerInfo);
        model.addAttribute("activityUser", activityUser);
        model.addAttribute("data", data);
        return managerPage("activityUser/list");
    }
    /*
     * 功能描述:根据活动id查询报名用户
     * @param:  * @param model
     * @param id
     * @param page
     * @param size
     * @return: java.lang.String
     * @auther: duyuanyuan
     * @date: 2019/3/18 14:15
     */
    @RequestMapping("/findQueryByActivityId")
    public String findQueryByActivityId(Model model,String id,
                                        @RequestParam(value = "page", defaultValue = "0") Integer page,
                                        @RequestParam(value = "size", defaultValue = "50") Integer size){
        ActivityUser activityUser=new ActivityUser();
        activityUser.setActivityId(id);
        Integer managerInfo = getManagerInfo();
        Page<ActivityUser> data = activityUserService.findList(page,size,activityUser,managerInfo);
        model.addAttribute("activityUser", new ActivityUser());
        model.addAttribute("data", data);
        return managerPage("activityUser/list");
    }
    /*
     * 功能描述:修改活动报名用户审核状态
     * @param:  * @param id
     * @param status
     * @return: java.lang.String
     * @auther: duyuanyuan
     * @date: 2019/3/18 10:56
     */
    @RequestMapping("/editStatus")
    public String edit(String id, Integer status) {
        activityUserService.updateStatus(id,status);
        return redirect("/activityUser/list");
    }
    @RequestMapping("/edit")
    public String edit(Model model, String id, String editType) {
        ActivityUser user = new ActivityUser();

        if (Consts.EditType.EDIT.equals(editType)) user = activityUserService.getById(id);

        model.addAttribute("activityUser", user);
        model.addAttribute("editType", editType);
        return managerPage("activityUser/edit");
    }
    /*
     * 功能描述:删除活动报名用户信息
     * @param:  * @param id
     * @return: java.lang.String
     * @auther: duyuanyuan
     * @date: 2019/3/18 10:56
     */
    @RequestMapping("/delete")
    public String delete(String id) {
        if (Misc.isEmpty(id)) return toJson(false, "id信息为空", null);
        activityUserService.deleteActivityUser(id);
        return redirect("/activityUser/list");
    }
}
